package org.eclipseuseradmin.internal.ui.wizards;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipseuseradmin.internal.ui.WizardElement;

public class WizardLabelProvider extends LabelProvider implements
		ILabelProvider {

	@Override
	public Image getImage(Object element) {

		if (element instanceof WizardElement) {
			return getImage(((WizardElement) element).getImageDescriptor());
		}

		return null;
	}

	@Override
	public String getText(Object element) {

		if (element instanceof WizardElement) {
			return ((WizardElement) element).getName();
		}

		return null;
	}

	private Image getImage(ImageDescriptor imageDescriptor) {

		if (imageDescriptor == null) {
			return null;
		}
		return imageDescriptor.createImage();
	}

}
